/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jollylengkono.skripsi.CollaborativeWorksComment.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jollylengkono.skripsi.dao.CollaborativeWorksCommentDao;
import jollylengkono.skripsi.dao.CollaborativeWorksDao;
import jollylengkono.skripsi.CollaborativeWorksComment.form.CollaborativeWorksCommentUpdateForm;
import jollylengkono.skripsi.model.CollaborativeWorks;
import jollylengkono.skripsi.model.CollaborativeWorksComment;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author hp02
 */
public class CollaborativeWorksCommentUpdate extends Action {

    private String FORWARD;
    private int STATE;

    public CollaborativeWorksCommentUpdate() {
    }

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) {
        HttpSession sess = request.getSession(true);
        Members commentator = (Members) sess.getAttribute("memberSessObject");
        
        CollaborativeWorksCommentUpdateForm commentForm = (CollaborativeWorksCommentUpdateForm) form;
        CollaborativeWorksComment comment = new CollaborativeWorksComment();
        
        comment.setId(commentForm.getId());
        comment.setCollaborativeWork((CollaborativeWorks) new CollaborativeWorksDao().read(commentForm.getIdCollaborativeWork()));
        comment.setComment(commentForm.getComment());
        comment.setCommentator(commentator);
        comment.setDateUpdate(commentForm.getDateUpdate());
        comment.setDatePublish(commentForm.getDatePublish());
        comment.setDateUpdate(commentForm.getDateUpdate());
        comment.setReplyFor((CollaborativeWorksComment) new CollaborativeWorksCommentDao().read(commentForm.getIdReplyFor()));
        comment.setStatus(commentForm.getStatus());
        
        this.STATE = new CollaborativeWorksCommentDao().update(comment);
        if(this.STATE==1) {
            this.FORWARD = "success";
        } else {
            this.FORWARD = "fail";
        }
        return mapping.findForward(FORWARD);
    }
    
    
}
